import { reactive } from "vue";
import type { FormItemConfig } from "@/components/DynamicForm/types";

export function useVulnerForm() {
  // 搜索表单数据
  const searchFormData = reactive({
    taskName: "", // 漏洞名称
    creater: "", // 漏洞等级
    ipscope: "", // 与我有关
  });

  // 搜索表单配置
  const searchFormConfig: FormItemConfig[] = [
    {
      key: "taskName",
      name: "漏洞名称",
      type: "input",
      placeholder: "漏洞名称",
      params: {
        maxLength: 30,
        clearable: true,
      },
    },
    {
      key: "creater",
      name: "漏洞等级",
      type: "select",
      placeholder: "漏洞等级",
      options: [
        { label: "高危", value: "高危" },
        { label: "中危", value: "中危" },
        { label: "低危", value: "低危" },
      ],
      params: {
        clearable: true,
      },
    },
    {
      key: "ipscope",
      name: "与我有关",
      type: "select",
      placeholder: "与我有关",
      options: [
        { label: "是", value: "是" },
        { label: "否", value: "否" },
      ],
      params: {
        clearable: true,
      },
    },
  ];

  // 获取搜索参数
  const getSearchParams = () => {
    return {
      taskName: searchFormData.taskName,
      creater: searchFormData.creater,
      ipscope: searchFormData.ipscope,
    };
  };

  return {
    // 数据
    searchFormData,

    // 配置
    searchFormConfig,

    // 方法
    getSearchParams,
  };
}
